package b.i.k;

import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Build.VERSION;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.WindowInsets;
import android.view.WindowInsets.Builder;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Objects;

/* compiled from: WindowInsetsCompat */
public class x {
    public static final x b;
    public final h a;

    /* compiled from: WindowInsetsCompat */
    public static class c {
        public final x a = new x(null);

        public x a() {
            throw null;
        }

        public void b(b.i.d.b bVar) {
        }

        public void c(b.i.d.b bVar) {
            throw null;
        }
    }

    /* compiled from: WindowInsetsCompat */
    public static class h {
        public final x a;

        public h(x xVar) {
            this.a = xVar;
        }

        public x a() {
            return this.a;
        }

        public x b() {
            return this.a;
        }

        public x c() {
            return this.a;
        }

        public c d() {
            return null;
        }

        public b.i.d.b e() {
            return g();
        }

        public boolean equals(Object obj) {
            boolean z = true;
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof h)) {
                return false;
            }
            h hVar = (h) obj;
            if (!(j() == hVar.j() && i() == hVar.i() && Objects.equals(g(), hVar.g()) && Objects.equals(f(), hVar.f()) && Objects.equals(d(), hVar.d()))) {
                z = false;
            }
            return z;
        }

        public b.i.d.b f() {
            return b.i.d.b.e;
        }

        public b.i.d.b g() {
            return b.i.d.b.e;
        }

        public x h(int i, int i2, int i3, int i4) {
            return x.b;
        }

        public int hashCode() {
            return Objects.hash(new Object[]{Boolean.valueOf(j()), Boolean.valueOf(i()), g(), f(), d()});
        }

        public boolean i() {
            return false;
        }

        public boolean j() {
            return false;
        }
    }

    /* compiled from: WindowInsetsCompat */
    public static class a extends c {
        public static Field c = null;
        public static boolean d = false;
        public static Constructor<WindowInsets> e = null;
        public static boolean f = false;
        public WindowInsets b;

        public a() {
            String str = "WindowInsetsCompat";
            if (!d) {
                try {
                    c = WindowInsets.class.getDeclaredField("CONSUMED");
                } catch (ReflectiveOperationException e) {
                    Log.i(str, "Could not retrieve WindowInsets.CONSUMED field", e);
                }
                d = true;
            }
            Field field = c;
            WindowInsets windowInsets = null;
            if (field != null) {
                try {
                    WindowInsets windowInsets2 = (WindowInsets) field.get(null);
                    if (windowInsets2 != null) {
                        windowInsets = new WindowInsets(windowInsets2);
                        this.b = windowInsets;
                    }
                } catch (ReflectiveOperationException e2) {
                    Log.i(str, "Could not get value from WindowInsets.CONSUMED field", e2);
                }
            }
            if (!f) {
                try {
                    e = WindowInsets.class.getConstructor(new Class[]{Rect.class});
                } catch (ReflectiveOperationException e22) {
                    Log.i(str, "Could not retrieve WindowInsets(Rect) constructor", e22);
                }
                f = true;
            }
            Constructor constructor = e;
            if (constructor != null) {
                try {
                    windowInsets = (WindowInsets) constructor.newInstance(new Object[]{new Rect()});
                } catch (ReflectiveOperationException e222) {
                    Log.i(str, "Could not invoke WindowInsets(Rect) constructor", e222);
                }
            }
            this.b = windowInsets;
        }

        public x a() {
            return x.j(this.b);
        }

        public void c(b.i.d.b bVar) {
            WindowInsets windowInsets = this.b;
            if (windowInsets != null) {
                this.b = windowInsets.replaceSystemWindowInsets(bVar.a, bVar.b, bVar.c, bVar.d);
            }
        }

        public a(x xVar) {
            this.b = xVar.i();
        }
    }

    /* compiled from: WindowInsetsCompat */
    public static class b extends c {
        public final Builder b;

        public b() {
            this.b = new Builder();
        }

        public x a() {
            return x.j(this.b.build());
        }

        public void b(b.i.d.b bVar) {
            this.b.setStableInsets(Insets.of(bVar.a, bVar.b, bVar.c, bVar.d));
        }

        public void c(b.i.d.b bVar) {
            this.b.setSystemWindowInsets(Insets.of(bVar.a, bVar.b, bVar.c, bVar.d));
        }

        public b(x xVar) {
            Builder builder;
            WindowInsets i = xVar.i();
            if (i != null) {
                builder = new Builder(i);
            } else {
                builder = new Builder();
            }
            this.b = builder;
        }
    }

    /* compiled from: WindowInsetsCompat */
    public static class d extends h {
        public final WindowInsets b;
        public b.i.d.b c = null;

        public d(x xVar, WindowInsets windowInsets) {
            super(xVar);
            this.b = windowInsets;
        }

        public final b.i.d.b g() {
            if (this.c == null) {
                this.c = b.i.d.b.a(this.b.getSystemWindowInsetLeft(), this.b.getSystemWindowInsetTop(), this.b.getSystemWindowInsetRight(), this.b.getSystemWindowInsetBottom());
            }
            return this.c;
        }

        public x h(int i, int i2, int i3, int i4) {
            c bVar;
            x j = x.j(this.b);
            if (VERSION.SDK_INT >= 29) {
                bVar = new b(j);
            } else {
                bVar = new a(j);
            }
            bVar.c(x.f(g(), i, i2, i3, i4));
            bVar.b(x.f(f(), i, i2, i3, i4));
            return bVar.a();
        }

        public boolean j() {
            return this.b.isRound();
        }
    }

    /* compiled from: WindowInsetsCompat */
    public static class e extends d {
        public b.i.d.b d = null;

        public e(x xVar, WindowInsets windowInsets) {
            super(xVar, windowInsets);
        }

        public x b() {
            return x.j(this.b.consumeStableInsets());
        }

        public x c() {
            return x.j(this.b.consumeSystemWindowInsets());
        }

        public final b.i.d.b f() {
            if (this.d == null) {
                this.d = b.i.d.b.a(this.b.getStableInsetLeft(), this.b.getStableInsetTop(), this.b.getStableInsetRight(), this.b.getStableInsetBottom());
            }
            return this.d;
        }

        public boolean i() {
            return this.b.isConsumed();
        }
    }

    /* compiled from: WindowInsetsCompat */
    public static class f extends e {
        public f(x xVar, WindowInsets windowInsets) {
            super(xVar, windowInsets);
        }

        public x a() {
            return x.j(this.b.consumeDisplayCutout());
        }

        public c d() {
            DisplayCutout displayCutout = this.b.getDisplayCutout();
            if (displayCutout == null) {
                return null;
            }
            return new c(displayCutout);
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof f)) {
                return false;
            }
            return Objects.equals(this.b, ((f) obj).b);
        }

        public int hashCode() {
            return this.b.hashCode();
        }
    }

    /* compiled from: WindowInsetsCompat */
    public static class g extends f {
        public b.i.d.b e = null;

        public g(x xVar, WindowInsets windowInsets) {
            super(xVar, windowInsets);
        }

        public b.i.d.b e() {
            if (this.e == null) {
                Insets mandatorySystemGestureInsets = this.b.getMandatorySystemGestureInsets();
                this.e = b.i.d.b.a(mandatorySystemGestureInsets.left, mandatorySystemGestureInsets.top, mandatorySystemGestureInsets.right, mandatorySystemGestureInsets.bottom);
            }
            return this.e;
        }

        public x h(int i, int i2, int i3, int i4) {
            return x.j(this.b.inset(i, i2, i3, i4));
        }
    }

    static {
        c bVar;
        if (VERSION.SDK_INT >= 29) {
            bVar = new b();
        } else {
            bVar = new a();
        }
        b = bVar.a().a.a().a.b().a.c();
    }

    public x(WindowInsets windowInsets) {
        int i = VERSION.SDK_INT;
        if (i >= 29) {
            this.a = new g(this, windowInsets);
        } else if (i >= 28) {
            this.a = new f(this, windowInsets);
        } else {
            this.a = new e(this, windowInsets);
        }
    }

    public static b.i.d.b f(b.i.d.b bVar, int i, int i2, int i3, int i4) {
        int max = Math.max(0, bVar.a - i);
        int max2 = Math.max(0, bVar.b - i2);
        int max3 = Math.max(0, bVar.c - i3);
        int max4 = Math.max(0, bVar.d - i4);
        if (max == i && max2 == i2 && max3 == i3 && max4 == i4) {
            return bVar;
        }
        return b.i.d.b.a(max, max2, max3, max4);
    }

    public static x j(WindowInsets windowInsets) {
        Objects.requireNonNull(windowInsets);
        return new x(windowInsets);
    }

    public int a() {
        return e().d;
    }

    public int b() {
        return e().a;
    }

    public int c() {
        return e().c;
    }

    public int d() {
        return e().b;
    }

    public b.i.d.b e() {
        return this.a.g();
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof x)) {
            return false;
        }
        return Objects.equals(this.a, ((x) obj).a);
    }

    public boolean g() {
        return this.a.i();
    }

    @Deprecated
    public x h(int i, int i2, int i3, int i4) {
        c bVar;
        if (VERSION.SDK_INT >= 29) {
            bVar = new b(this);
        } else {
            bVar = new a(this);
        }
        bVar.c(b.i.d.b.a(i, i2, i3, i4));
        return bVar.a();
    }

    public int hashCode() {
        h hVar = this.a;
        return hVar == null ? 0 : hVar.hashCode();
    }

    public WindowInsets i() {
        h hVar = this.a;
        return hVar instanceof d ? ((d) hVar).b : null;
    }

    public x(x xVar) {
        this.a = new h(this);
    }
}
